<div class="layuimini-container layuimini-page-anim">
    <div class="layuimini-main layui-form">


        <script type="text/html" id="toolbarDemo">
            <div class="layui-btn-container">
                <button class="layui-btn layui-btn-sm layui-btn-danger data-delete-btn" lay-event="delete"> 批量删除 </button>
            </div>
        </script>

        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>

        <script type="text/html" id="currentTableBar">
            <a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete" lay-event="delete">删除</a>
        </script>

    </div>
</div>

<script>
    layui.use(['form', 'table','miniPage','element','laydate'], function () {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table,
            laydate=layui.laydate,
            miniPage = layui.miniPage;

        // 日期
        /*laydate.render({
            elem: '#clockTime',
            trigger:'click'
        });*/

        table.render({
            elem: '#currentTableId',
            url:  'clockin/queryClockInAll',
            toolbar: '#toolbarDemo',
            defaultToolbar: ['filter', 'exports', 'print', {
                title: '提示',
                layEvent: 'LAYTABLE_TIPS',
                icon: 'layui-icon-tips'
            }],
            cols: [[
                {type: "checkbox", width: 50},
                //{field: 'id', width: 80, title: 'ID', sort: true},
                {templet:'<div>{{d.owner.username}}</div>',width: 80, title: '业主'},
                {templet:'<div>{{d.owner.tel}}</div>',width: 120, title: '联系电话'},
                {templet:'<div>{{d.building.numbers}}</div>',width: 80, title: '楼栋'},
                {templet:'<div>{{d.building.uints}}</div>',width: 80, title: '单元'},
                {templet:'<div>{{d.house.numbers}}</div>',width: 100, title: '房间号'},
                {field: 'clockInTime', width: 120, title: '打卡时间'},
                {title: '操作', minWidth: 150, toolbar: '#currentTableBar', align: "center"}
            ]],
            limits: [10, 15, 20, 25, 50, 100],
            limit: 15,
            page: true,
            skin: 'line',
            id: 'testReload'
        });


        /*var $ = layui.$, active = {
                reload: function(){
                    var clockInTime = $('#clockTime');
                    //执行重载
                    table.reload('testReload', {
                        page: {
                            curr: 1 //重新从第 1 页开始
                        }
                        ,where: {
                            clockInTime:clockInTime.val()
                        }
                    }, 'data');
                }
        };*/


        $('.demoTable .layui-btn').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

        // 监听搜索操作
        form.on('submit(data-search-btn)', function (data) {
            var result = JSON.stringify(data.field);
            layer.alert(result, {
                title: '最终的搜索信息'
            });

            //执行搜索重载
            table.reload('currentTableId', {
                page: {
                    curr: 1
                }
                , where: {
                    searchParams: result
                }
            }, 'data');

            return false;
        });

        /**
         * toolbar事件监听
         */
        table.on('toolbar(currentTableFilter)', function (obj) {
            if (obj.event === 'delete') {  // 监听删除操作
                /*
                  1、判断是否有选择记录 如果没有提示
                  2、获取要删除的id集合
                  3、发送请求 实现删除功能
                  4、提示成功 并刷新主页
                 */
                var checkStatus=table.checkStatus(obj.config.id);
                var data =checkStatus.data;
                if(data.length==0){
                    layer.msg("请选择要删除的记录信息");
                }else{
                    //获取要删除id的集合
                    var ids =getCheckId(data);
                    layer.confirm('你确定要删除记录吗？',function (index) {
                        //执行删除功能
                        deleteByIds($,"clockin/deleteByIds",ids,index);
                    })

                }

            }
        });



        //监听表格复选框选择
        table.on('checkbox(currentTableFilter)', function (obj) {
            console.log(obj)
        });


        table.on('tool(currentTableFilter)', function (obj) {
            var data = obj.data;
            if (obj.event === 'delete') {
                layer.confirm('确定是否删除', function (index) {
                    deleteByIds($,"clockin/deleteByIds",data.id,index)
                });
            }
        });

    });
</script>